<?php    
    define('PIXEL_MODE', 'development');
    require "../pixel/config/environment.php";
    #$GLOBALS['PIXEL']['DEBUG_LEVEL'] = 1;
    require "../pixel/scripts/installer.php";			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Language" content="en-us" />
		
		<title>Pixel App Installer</title>				
		<?php echo javascript_defaults()?>
		
		<style type="text/css" media="screen">
		  /* <![CDATA[ */
          /* yahoo css reset-fonts-grids */
          /*reset.css*/body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}ol,ul {list-style:none;}caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
          /*fonts.css*/body{font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
          /*grids.css*/body{text-align:center;}#ft{clear:both;}#doc,#doc2,#doc3,.yui-t1,.yui-t2,.yui-t3,.yui-t4,.yui-t5,.yui-t6,.yui-t7{margin:auto;text-align:left;width:57.69em;*width:56.3em;min-width:750px;}#doc2{width:73.074em;*width:71.313em;min-width:950px;}#doc3{margin:auto 10px;width:auto;}.yui-b{position:relative;}.yui-b{_position:static;}#yui-main .yui-b{position:static;}#yui-main{width:100%;}.yui-t1 #yui-main,.yui-t2 #yui-main,.yui-t3 #yui-main{float:right;margin-left:-25em;}.yui-t4 #yui-main,.yui-t5 #yui-main,.yui-t6 #yui-main{float:left;margin-right:-25em;}.yui-t1 .yui-b{float:left;width:12.3207em;*width:12.0106em;}.yui-t1 #yui-main .yui-b{margin-left:13.3207em;*margin-left:13.0106em;}.yui-t2 .yui-b{float:left;width:13.8456em;*width:13.512em;}.yui-t2 #yui-main .yui-b{margin-left:14.8456em;*margin-left:14.512em;}.yui-t3 .yui-b{float:left;width:23.0759em;*width:22.52em;}.yui-t3 #yui-main .yui-b{margin-left:24.0759em;*margin-left:23.52em;}.yui-t4 .yui-b{float:right;width:13.8456em;*width:13.512em;}.yui-t4 #yui-main .yui-b{margin-right:14.8456em;*margin-right:14.512em;}.yui-t5 .yui-b{float:right;width:18.4608em;*width:18.016em;}.yui-t5 #yui-main .yui-b{margin-right:19.4608em;*margin-right:19.016em;}.yui-t6 .yui-b{float:right;width:23.0759em;*width:22.52em;}.yui-t6 #yui-main .yui-b{margin-right:24.0759em;*margin-right:23.52em;}.yui-t7 #yui-main .yui-b{display:block;margin:0 0 1em 0;}#yui-main .yui-b{float:none;width:auto;}.yui-g .yui-u,.yui-g .yui-g,.yui-gc .yui-u,.yui-gc .yui-g .yui-u,.yui-ge .yui-u,.yui-gf .yui-u{float:right;display:inline;}.yui-g div.first,.yui-gc div.first,.yui-gc div.first div.first,.yui-gd div.first,.yui-ge div.first,.yui-gf div.first{float:left;}.yui-g .yui-u,.yui-g .yui-g{width:49.1%;}.yui-g .yui-g .yui-u,.yui-gc .yui-g .yui-u{width:48.1%;}.yui-gb .yui-u,.yui-gc .yui-u,.yui-gd .yui-u{float:left;margin-left:2%;*margin-left:1.895%;width:32%;}.yui-gb div.first,.yui-gc div.first,.yui-gd div.first{margin-left:0;}.yui-gc div.first,.yui-gd .yui-u{width:66%;}.yui-gd div.first{width:32%;}.yui-ge .yui-u{width:24%;}.yui-ge div.first,.yui-gf .yui-u{width:74.2%;}.yui-gf div.first{width:24%;}.yui-ge div.first{width:74.2%;}#bd:after,.yui-g:after,.yui-gb:after,.yui-gc:after,.yui-gd:after,.yui-ge:after,.yui-gf:after{content:".";display:block;height:0;clear:both;visibility:hidden;}#bd,.yui-g,.yui-gb,.yui-gc,.yui-gd,.yui-ge,.yui-gf{zoom:1;}

  /* welcome css */
  #doc3 {
      margin:0;
  }
  body {
      background: #777;
      color:#fff;
  }
  #header {
      height:48px;
      background:#000;
      border-bottom:1px solid #fff;
  }
  #wrap {
      border:15px solid #888;
      border-top:1px;
      width:600px;
      padding:15px;
      margin:auto;
      background:#eeebea;
      color:#000;
      font-size:110%;
  }
  h1 {
      border-top:15px solid #333;
      border-bottom:1px solid #999;
      color:#fff;
      background:#ce8c19;
      padding:0.5em;
      text-align:center;
      font-size:130%;
      font-family:georgia,times,serif;
      font-weight:bold;
      letter-spacing:0.1em;
  }
  h2 {
      margin:0.5em 0 1em 0;
      font-weight:bold;
      font-size:120%;
  }
  
  h2.error {
      background:#df0024 url(images/admin/warn.png) 0 45% no-repeat;
      color:#fff;
      padding:0.5em;
      padding-left:2em;
  }

  ol {
      list-style-type:decimal;
      margin-left:20px;
      padding-left:20px;
  }
  li {
      line-height:1.2em;
      margin-bottom:1.3em;
  }
  p {
      line-height:1.2em;
      margin-bottom:1.3em;
  }
  p#install-me {
      color:#fff;
      font-weight:bold;
      font-size:110%;
      background:#5bbc2b;
      text-align:center;
      margin-bottom:1em;
  }
  p#install-me a {
      color:#fff;
      display:block;
      text-decoration:none;
      padding:15px;
  }
  p#install-me a:hover {
      background:#ce8c19;
  }
  /* ]]> */
  </style>
  <link rel="stylesheet" href="<?php echo get_installed_path() ?>/css/forms.css" type="text/css" media="screen" title="no title" charset="utf-8" />					
	</head>
	
	<body id="">
    	    <div id='doc3'>
    	    <div id="header" class='yui-b'>
    	       <img src="images/logo.gif" width="195" height="48" alt="Logo">
    	    </div>
    	    <h1>Installing Pixel-App</h1>
	    
        <div id='wrap'>
	    <div id='step_message'>
	    <?php 
	    $success_text = false;
	    if ( $_POST['action'] == 'next_step' )
    	{
    	    $errors = array();
    	    // validate input
    	    do {
    	        if ( empty($_POST['first_name']) )
    	        {
    	            $errors['first_name'] = 'First Name can not be blank.';
    	        }
    	        if ( empty($_POST['last_name']) )
    	        {
    	            $errors['last_name'] = 'Last Name can not be blank.';
    	        }
    	        if ( !is_valid_email($_POST['email']) )
    	        {
    	            $errors['email'] = 'Email address is invalid.';
    	        }
    	        if ( strlen($_POST['user_password'])<6 )
    	        {
    	            $errors['password'] = 'Your password must be at least 6 characters long.';
    	        }
    	        if( sizeof($errors) > 0 ) break;
    	        $success_text = install_pixel_app();
    	    } while(0);
    	    
    	    if ( !empty($errors) )
    	    {
    	        $header_tag = "h2";
            	$id			= 'error';
            	$class		= 'div_form_error_list';    	    	

        		$header = content_tag($header_tag,'Error!',array('class'=>'error'));
        		$body   = content_tag('p','Your form contained the following errors:');
        		foreach( $errors as $key => $value )
        		{
        		    $key     = ucwords(str_replace("_"," ",$key));
        			$f_errors .= content_tag('li',"$key: $value");
        		}
        		$error_list = content_tag('ul',$f_errors);
        		echo content_tag('div',$header.$body.$error_list,array('class'=>$class,'id'=>$id));
    	    }
	    }
	    // did it install?
	    if ($success_text) 
	    {
	        echo $success_text;
	    } else { 
	        if (!pre_flight_check()) {
        ?>
        <h2 class='error'>Install Errors</h2>
        <p>Before you begin, you will have to take care of the following things:</p>
        <div class='div_form_error_list'>
        <ul><?php foreach($pre_install_errors as $e) { echo "<li>$e</li>";} ?></ul>
        </div>
        <?php
            if ($already_installed) {
        ?>
        <p id='install-me'><a href="<?php echo get_installed_path(); ?>/login">Login to your admin area &raquo;</a></p>
        <?php
            } else {
        ?>
        <p id='install-me'><a href="#" onclick="javascript:window.location.reload(false);return false">Refresh the page when you have made the changes. &raquo;</a></p>
        <?php } ?>
        <?php	            
	        } else {
	    ?>	     
        <h2>Step One</h2>
	    <p>Please fill out the following fields:</p>
	    <?php echo  form_tag(get_installed_path().'/install.php',array('id'=>'install-form')) ?>
	                                
	    <?php echo  hidden_field_tag('action','next_step') ?>
	    <ol>	       
	       <li><b>First Name:</b><br>
	           <?php echo  text_field_tag('first_name', $_POST['first_name'], array('class'=>'required','size'=>40)) ?></li>
	       <li><b>Last Name:</b><br>
	           <?php echo  text_field_tag('last_name', $_POST['last_name'], array('class'=>'required','size'=>40)) ?></li>
	       <li><b>Email address:</b><br>
	           <?php echo  text_field_tag('email', $_POST['email'], array('class'=>'required validate-email','size'=>40)) ?></li>

	       <li><b>Desired password:</b> (must be at least 6 characters long)<br>
	           <?php echo text_field_tag('user_password', $_POST['user_password'], array('class'=>'validate-password','size'=>40))?>
	    </ol>	
	    <p style='text-align:center;'><?php echo  submit_tag('Next >>') ?></p>    
	    <?php echo  end_form_tag() ?>
	    <?php echo validate_form('install-form') ?>

	        <?php } ?>
	    <?php } ?>
        </div>
	    </div>  
	    <p style='text-align:center'>&copy; 2005 - <?php echo date("Y") ?> thebusypixel.com</p>
	    </div>  
	</body>
</html>

